<?php

namespace App\Http\Controllers\Api\Client;

use App\Http\Controllers\Controller;
use App\Models\House;
use Illuminate\Http\Request;
use App\Models\Api\Favorites as FavoritesModes;
use Illuminate\Support\Facades\DB;


class Favorites extends Controller
{
    //收藏

    //获取用户收藏的房源
    public function getUserFavoritesList(Request $request){
        $request->user_id;
        $uid=$request->input('id');
        if (empty($uid)){
            return ['code'=>30304,'msg'=>'登录失效','data'=>''];
        }
        //收藏
        $titles = FavoritesModes::where('uid',$uid)->orderBy('created_at', 'desc')->pluck('fid');
        if (empty($titles)){
             return ['code'=>30204,'msg'=>'收藏记录为空','data'=>''];
        }
        $titles= $titles->toArray();
       //收藏的房源列表
        $collectList = House::whereIn('id', $titles)->get();
        return ['code'=>30200,'msg'=>'查询成功','data'=>$collectList];
    }
}
